#pragma once

#include "InstanceValue.h"

#include "InstanceSpecification.h"

namespace uml {

InstanceValue::InstanceValue(const QString& umlType)
    : ValueSpecification(umlType) {}

void InstanceValue::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ValueSpecification::fromJson(json, errorList);
    instance_ = JsonSerializable::create<InstanceSpecification>(json.value("instance"), errorList);

}

void InstanceValue::toJson(QJsonObject& json) {
    ValueSpecification::toJson(json);
    if (instance_) {
        QJsonObject instance_json;
        instance_->toJson(instance_json);
        json.insert("instance", instance_json);
    }
}

/// <summary>
/// instance getter
/// The InstanceSpecification that represents the specified value.
/// </summary>
shared_ptr<InstanceSpecification> InstanceValue::instance() const {
    return instance_;
}

/// <summary>
/// instance setter
/// The InstanceSpecification that represents the specified value.
/// </summary>
void InstanceValue::setInstance(shared_ptr<InstanceSpecification> value) {
    instance_ = value;
}

} // namespace uml
